package pl.textureStudio.data.vo
{
	import pl.textures.TextureType;

	import flash.display.Bitmap;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.getTimer;

	/**
	 * @author michalr
	 */
	public class StudioTextureVO
	{
		/** nazwa textury w systemie */
		public var textureID:String;
		/** typ textury */
		public var textureType:String;
		/** rozmiar textury */
		public var textureSize:Point;
		/** sciezka do textury */
		public var texturePath:String;
		/** sciezka do textury z dodatkowymi danymi */
		public var additionalTextureDataPath:String;
		/** glowna bitmapa */
		private var _texture:Bitmap;
		/** bitmapa z dodatkowymiDanymi */
		public var additionalTextureData:Bitmap;
		/** region jezeli textura pochodzi z texture pack'a */
		public var texturePackRegion:Rectangle;

		public static function factory( node:XML ):StudioTextureVO
		{
			var vo:StudioTextureVO = new StudioTextureVO();
			vo.textureID = node.@id;
			vo.textureType = node.@type;
			vo.textureSize = new Point( String( node.@size ).split( 'x' )[0], String( node.@size ).split( 'x' )[1] );
			vo.texturePath = node.@tpath;
			vo.additionalTextureDataPath = node.@atpath;
			if (node.@texturePackRegion != undefined)
			{
				var regions:Array = (String( node.@texturePackRegion )).split( ',' );
				vo.texturePackRegion = new Rectangle( regions[0], regions[1], regions[2], regions[3] );
			}
			return vo;
		}
		
		public function set texture(val:Bitmap):void
		{
			_texture = val;
			textureSize = new Point(val.width,val.height);
		}
		
		public function get texture():Bitmap
		{
			return _texture;
		}
		
		public static function factory2( path:String):StudioTextureVO
		{
			var vo:StudioTextureVO = new StudioTextureVO();
			vo.textureID = 'randomTexture_' + getTimer();
			vo.textureType = TextureType.STATIC_OBSTACLE;
			vo.textureSize = new Point();
			vo.texturePath = path;
			vo.additionalTextureDataPath = null;
			return vo;
		}
	}
}
